<!-- saved from url=(0022)http://internet.e-mail -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>For Statement</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../edit68k.css" rel="stylesheet" type="text/css">
</head>

<body class="text">
<p class="heading">Structured Control - For <br>
<hr noshade>
<p><b>For</b> - Utilizes op1 as a counter and loops while op1 is 
between the values of op2 and op3 inclusive. Loops may be written that count up 
(TO) or down (DOWNTO). The user may specify the step size with op4. If no step 
size is specified a default step size of #1 is used.</p>
<p>The For statement has the following syntax:</p>
<p class="sourcecode">FOR[.<i>size</i>] <i>op1</i> = <i>op2</i> TO 
<i>op3</i>&nbsp; [BY <i>op4</i>]&nbsp; DO[.<i>extent</i>]<br>
&nbsp;&nbsp; <i>code</i>&nbsp;<br>
ENDF</p>
<p>or</p>
<p class="sourcecode">FOR[.<i>size</i>] <i>op1</i> = <i>op2</i> DOWNTO <i>op3</i>&nbsp; [BY 
<i>op4</i>]&nbsp; DO[.<i>extent</i>]<br>
&nbsp;&nbsp; <i>code</i><br>
ENDF</p>
<p><i><b>size</b></i> - Optional B, W, or L, specifying the size
of the operand comparison.&nbsp; These values correspond to the Byte, Word, or Long word data size. 
If any of the four operands is an address register, <b><i>size</i></b> may not be B (byte).</p>
<p><i><b>op1</b></i> - The counter register.&nbsp; Must be an
addressing mode that allows modification of the destination.</p>
<p><i><b>op2</b></i> - The initial number to be stored in <i><b>op1</b></i>.&nbsp;
May be any addressing mode.</p>
<p><i><b>op3</b></i> - The number to be counted up/down to.&nbsp;
The direction of count is specified by either <b>TO</b> or <b>DOWNTO</b>.&nbsp;
May be any addressing mode.</p>
<p><i><b>op4</b></i> - Optional amount to step by.&nbsp; If
omitted, you must NOT include the <b>BY</b> keyword.&nbsp; The step defaults to
one.&nbsp; May be any addressing mode.</p>
<p><i><b>extent</b></i> - Optional value S or L, indicating the size of 
the forward branch to use (short or long).</p>
<p><i><b>code</b></i> - The series of assembly commands executed until the 
counter <i><b>op1</b></i> equals <i><b>op3</b></i>.</p>
<p>One space should be used to separate each part of the statement.</p>
<p class="subheading">===Notes===</p>
<p>Immediate numbers may be used for <i><b>op2</b></i>, <i><b>op3</b></i>, and <i><b>
op4</b></i>.&nbsp; To do this, simply place a # sign before the number. For 
example:</p>
<p class="sourcecode">&nbsp; FOR.L D1 = #7 TO #36 BY #2 DO.S<br>
&nbsp;&nbsp;&nbsp; <i>code</i><br>
&nbsp; ENDF</p>
<p>The FOR-TO loop is not executed if <i><b>op2</b></i> is
greater than <i><b>op3</b></i> upon entry.&nbsp; Similarly, the FOR-DOWNTO
loop is not executed if <i><b>op2</b></i> is less than <i><b>op3</b></i>. <br>
<br>
The FOR uses signed comparisons so the following code does not loop because #255 
is interpreted as -1 on byte size comparisons. Changing from FOR.B to FOR.W or 
FOR.L will correct the loop.</p>
<p class="sourcecode">&nbsp; FOR.B D1 = #1 TO #255 DO.S<br>
&nbsp;&nbsp;&nbsp; <i>code</i><br>
&nbsp; ENDF</p>
<p>The bits of the CCR (condition code register) are modified
before the <i><b>code</b></i> is run.</p>
</body>
</html>